﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.ComponentModel;
using BizAppFactory.Domain;

namespace BizAppFactory.DomainModel.CustomEditors.MethodEditor
{
    public class MethodEditor : System.Drawing.Design.UITypeEditor
    {
        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null) 
            {
                return UITypeEditorEditStyle.Modal;
            }
            
            return base.GetEditStyle(context);
        } 

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 
        {
            if (context != null && context.Instance != null && provider != null) 
            {
                MethodForm methodForm = new MethodForm();
                methodForm.EditedMethod = (Method)context.Instance;
                methodForm.ShowDialog();
            }
            
            return value;
        }      
    }
}
